#include "types.h"
string req;
string rsp;

static void init_case()
{
	for (int i=0; i<9753; i++)
	{
		req.append("1234567");
		rsp.append("abcdefg");
	}
}

#ifdef TEST_CLIENT

#include "client.h"

class MyClient : public reldt::Client
{
public:

	void on_disconn()
	{
		printf("disconned\n\n");
	}

	void on_finish()
	{
		printf("finished\n\n");
	}

	void on_recv(const char *msg, int msglen)
	{
		string tmp(msg, msglen);

		if (tmp != rsp)
		{
			printf("recv bad: %d bytes ===>>>\n%.*s\n\n", msglen, msglen, msg);
			return;
		}

		printf("recv succ\n\n");
	}
};

int main()
{
	MyClient client;
	int rc;

	init_case();

	rc = client.connect("127.0.0.1", 20000, "127.0.0.1", 10000);
	client.send(req.c_str(), req.size());

	getchar();
	return 0;
}

#endif

#ifdef TEST_CLIENT_IN6

#include "client_in6.h"

class MyClient : public reldt::Client_in6
{
public:

	void on_disconn()
	{
		printf("disconned\n\n");
	}

	void on_finish()
	{
		printf("finished\n\n");
	}

	void on_recv(const char *msg, int msglen)
	{
		string tmp(msg, msglen);

		if (tmp != rsp)
		{
			printf("recv bad: %d bytes ===>>>\n%.*s\n\n", msglen, msglen, msg);
			return;
		}

		printf("recv succ\n\n");
	}
};

int main()
{
	MyClient client;
	int rc;

	init_case();

	rc = client.connect("::1", 20000, "::1", 10000);
	client.send(req.c_str(), req.size());

	getchar();
	return 0;
}

#endif

#ifdef TEST_SERVER

#include "server.h"

class MyServer : public reldt::Server
{
public:

	void on_disconn()
	{
		printf("disconned\n\n");
	}

	void on_finish()
	{
		printf("finished\n\n");
		this->disconn();
	}

	void on_recv(const char *msg, int msglen)
	{
		string tmp(msg, msglen);

		if (tmp != req)
		{
			printf("recv bad: %d bytes ===>>>\n%.*s\n\n", msglen, msglen, msg);
			return;
		}

		printf("recv succ\n\n");
		this->send(rsp.c_str(), rsp.size());
	}
};

int main()
{
	MyServer server;
	int rc;

	init_case();

	rc = server.accept("127.0.0.1", 10000, 0);

	getchar();
	return 0;
}

#endif

#ifdef TEST_SERVER_IN6

#include "server_in6.h"

class MyServer : public reldt::Server_in6
{
public:

	void on_disconn()
	{
		printf("disconned\n\n");
	}

	void on_finish()
	{
		printf("finished\n\n");
		this->disconn();
	}

	void on_recv(const char *msg, int msglen)
	{
		string tmp(msg, msglen);

		if (tmp != req)
		{
			printf("recv bad: %d bytes ===>>>\n%.*s\n\n", msglen, msglen, msg);
			return;
		}

		printf("recv succ\n\n");
		this->send(rsp.c_str(), rsp.size());
	}
};

int main()
{
	MyServer server;
	int rc;

	init_case();

	rc = server.accept("::1", 10000, 0);

	getchar();
	return 0;
}

#endif
